package cs.sy.service.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import cs.sy.service.bean.UserBean;
import cs.sy.service.business.UserLoginBuss;

public class CheckNameServlet extends HttpServlet{

	private static final long serialVersionUID = 1L;
	private final Log log = LogFactory.getLog(CheckNameServlet.class);
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		String status = "ok";
		try{
			String name = req.getParameter("name");
			UserBean result = new UserLoginBuss().getUserByName(name);
			if(result != null){
				status = "error";
			}
		}catch (Exception e) {
			log.error("...",e);
			status = "error";
		}
		PrintWriter out = resp.getWriter();
		resp.setContentType("text/html");
		out.print(status);
		out.flush();
		out.close();
	}
}
